#define NB_FLT_OUT 6
#define NB_INT_OUT 107
#define NB_FLT_IN_MAX 128
#define NB_INT_IN_MAX 128
#define DATA_OUT_SIZE 13+2+4+2//ViolinSolo

#include "UDPSocket.h"
#include "CanCard.h"
#include "cal_bits.h"
#include "Clock.h"
#include <iostream>
#include <windows.h>
#include "CarHDC.h"
#include "VEN/VEN2.h"

void sendUDPPacket(UDPSocket* s, float* fltData, int numberFlt, int* intData, int numberInt)
{
	int bufferSize = 2 * sizeof(int) + sizeof(float)*numberFlt + sizeof(int)*numberInt;
	unsigned char* buffer = new unsigned char[bufferSize];

	int offset = 0;

	*reinterpret_cast<int*>(&buffer[offset]) = numberFlt;
	offset += 4;

	for (int i = 0; i<numberFlt; i++)
	{
		*reinterpret_cast<float*>(&buffer[offset]) = fltData[i];
		offset += 4;
	}

	*reinterpret_cast<int*>(&buffer[offset]) = numberInt;
	offset += 4;

	for (int i = 0; i<numberInt; i++)
	{
		*reinterpret_cast<int*>(&buffer[offset]) = intData[i];
		offset += 4;
	}
	s->send(buffer, bufferSize);
	delete[] buffer;
}

bool recieveUDPPacket(UDPSocket* s, float* inFlt, int& nbFlt, int* inInt, int& nbInt)
{
	#define IN_BUFFER_SIZE (2*sizeof(int) + NB_FLT_IN_MAX*sizeof(float)+NB_INT_IN_MAX*sizeof(int))
	unsigned char buffer[IN_BUFFER_SIZE];
	int rcvSize = s->receive(buffer, IN_BUFFER_SIZE);

	int offset = 0;

	if (rcvSize<int(offset + sizeof(int)))
		return false;

	nbFlt = *reinterpret_cast<int*>(&buffer[offset]);
	offset += 4;

	for (int i = 0; i<nbFlt; i++)
	{
		if (rcvSize<int(offset + sizeof(float)))
			return false;

		inFlt[i] = *reinterpret_cast<float*>(&buffer[offset]);
		offset += 4;
	}

	//the case where the number of integer values in not specified is valid
	if (rcvSize<int(offset + sizeof(int)))
		return true;

	nbInt = *reinterpret_cast<int*>(&buffer[offset]);
	offset += 4;

	for (int i = 0; i<nbInt; i++)
	{
		if (rcvSize<int(offset + sizeof(int)))
			return false;

		inInt[i] = *reinterpret_cast<int*>(&buffer[offset]);
		offset += 4;
	}
	return true;
}

int main(int argc, char* argv[])
{
	bool havecheck1 = false;
	bool havecheck2 = false;
	bool havecheck3 = false;
	int curData1 = 0;
	int curData2 = 0;
	int curData3 = 0;

	if (argc>2)
	{
		std::cout << "usage: " << argv[0] << " [local port]" << std::endl;
		Sleep(5000);
		return 1;
	}

	// Default port
	short localPort = 3232;

	// If a port is transmited by arguments use it
	if (argc == 2)
		localPort = (short)atoi(argv[1]);

	// UDP socket server creation
	UDPSocket* s = newUDPSocketServer(localPort);
	// Initialization of the PCAN card
	GenericCanCard* pcanUsb = NewCanCard(TCanPCan, 1, 1, true, 125000);

	s->setBlocking(false); // Non-blocking socket
	if (s->good())
	{
		std::cout << "Listening port: " << localPort << std::endl;
	}
	else
	{
		std::cout << "Error opening socket: " << localPort << std::endl;
		return 2;
	}

	float outFlt[NB_FLT_OUT];
	memset(outFlt, 0, sizeof(outFlt));

	int outInt[NB_INT_OUT];
	memset(outInt, 0, sizeof(outInt));

	int nbInPackets = 0;

	unsigned char wakeUpHDC[] = { 0x0E, 0x00, 0x03, 0x0C, 0x39, 0x00, 0x00, 0xAC };
	unsigned char playIndicatorSound[] = { 0x07, 0xD0 };
	unsigned char stopIndicatorSound[] = { 0x00, 0x00 };
	Clock timeSinceWakeUpHDC;
	Clock timeSinceIndicatorHDC;
	Clock timeSinceJoyPoll;

	// Joystick position
	JOYINFOEX joyinfo;
	memset(&joyinfo, 0, sizeof(joyinfo));
	joyinfo.dwSize = sizeof(JOYINFOEX);
	joyinfo.dwFlags = JOY_RETURNALL;

	int joyNumDevs = joyGetNumDevs();
	UINT joyIndex = 0;
	// Get the first joystick available
	for (int DeviceID = 0; DeviceID<joyNumDevs; DeviceID++)
	{
		JOYCAPS jc;
		MMRESULT ret = joyGetDevCaps(DeviceID, &jc, sizeof(jc));
		if (ret == JOYERR_NOERROR)
		{
			joyIndex = DeviceID;
			std::cout << "found joystick device: " << (const char*)jc.szPname << std::endl;
		}
	}

	// Initialization of the first joystick found
	if (joyGetPosEx(joyIndex, &joyinfo) == JOYERR_NOERROR)
		std::cout << "Joystick initialization: OK!" << std::endl;
	else
		std::cout << "Joystick initialization: No Joystick found!" << std::endl;
	
	//ViolinSolo
	int temp = 0;

	CarHDC* carHDC = new CarHDC();
	while (true)
	{
		Sleep(10);
		// Read joystick
		if (joyGetPosEx(joyIndex, &joyinfo) == JOYERR_NOERROR)
		{
			for (int i = 0; i < 32; i++)
				outInt[i] = GetBits((int)joyinfo.dwButtons, i, i); // 32 buttons for BU0836X
			outFlt[0] = joyinfo.dwXpos; // Gas
			outFlt[1] = joyinfo.dwYpos; // Brake
			outFlt[2] = joyinfo.dwZpos; // PRND
			outFlt[3] = joyinfo.dwRpos; // M+
			outFlt[4] = joyinfo.dwUpos; // M-
			// The frame below is used to be decisive (for analog values)
			outFlt[5] = outFlt[2] + (outFlt[3] + outFlt[4]) / 2; // joyinfo.dwVpos;
		}
		// Send the wakeUpHDC to wake up the HDC
		if (timeSinceWakeUpHDC.run() > 0.1)
		{
			timeSinceWakeUpHDC.init();
			pcanUsb->SendMsg(0x036, sizeof(wakeUpHDC), wakeUpHDC); // 10Hz (0.1s)
		}

		float inFlt[NB_FLT_IN_MAX];
		int nbFlt;
		int inInt[NB_INT_IN_MAX];
		int nbInt;

		// Get UDP Packets for com initialization
		while (recieveUDPPacket(s, inFlt, nbFlt, inInt, nbInt))
		{
			PlaySound(NULL, 0, 0); // Turn off sound (No ABS)
			if (nbFlt != 0)
			{
				// In hdrv file, the first 4 vehicle output channels are reserved for ABS triggered
				if ((inFlt[0] == 1.0) || (inFlt[1] == 1.0) || (inFlt[2] == 1.0) || (inFlt[3] == 1.0))
					PlaySound(TEXT("sound\\ABS.wav"), NULL, SND_LOOP | SND_ASYNC); // A sound is played and it is sent to the buttkicker component to reproduce ABS behavior (20Hz)
				if (nbFlt < 4)
					std::cout << "Warning: Some ABS channels are missing!" << std::endl;
			}
			else
				std::cout << "Warning: No ABS channels found!" << std::endl;
			nbInPackets++;
		};

		unsigned int ID;
		unsigned char Data[8];
		unsigned short DataLen = sizeof(Data);

		// CAN message processing
		if (pcanUsb->RcvMsg(ID, DataLen, Data))
		{
			switch (ID) // Network trame identifiant
			{
				case 0x094: // Trame HDC, 8 bytes
				{	
				// Start Lighting control
					int LC_leftPush = GetBits(Data[0], 0, 0);
					int LC_FogLess = GetBits(Data[0], 1, 1);
					int LC_FogMore = GetBits(Data[0], 2, 2);
					int LC_headLightFlash = GetBits(Data[0], 3, 3);
					int LC_dippedHighBeamReverter = GetBits(Data[0], 4, 4);
					int LC_positionLights = GetBits(Data[0], 6, 6);
					int LC_dippedBeamLights = GetBits(Data[0], 7, 7);
					int LC_Auto = GetBits(Data[0], 5, 5) && GetBits(Data[0], 6, 6) && GetBits(Data[0], 7, 7);
					int LC_stop = !LC_positionLights && !LC_dippedBeamLights;
					// Auto mode is not yet available in SCANeR.
					{
						if (LC_Auto)
						{
							// Force all lights to off
							carHDC->setLC_stop(1);
							carHDC->setLC_positionLights(0);
							carHDC->setLC_dippedBeamLights(0);
							outInt[32] = 1;
							outInt[33] = 0;
							outInt[34] = 0;
						}
						else
						{
							carHDC->setLC_stop(LC_stop);
							carHDC->setLC_positionLights(LC_positionLights);
							carHDC->setLC_dippedBeamLights(LC_dippedBeamLights);
							outInt[32] = LC_stop;
							outInt[33] = LC_positionLights;
							outInt[34] = LC_dippedBeamLights;
						}
					}
					//Head flashing lights / High Beam
					{
						int curHeadState = carHDC->getLC_dippedHighBeamReverter();
						outInt[35] = curHeadState;
						if (LC_dippedBeamLights)
						{
							if (LC_headLightFlash) // Flashing light
							{
								carHDC->setLC_headLightFlash(LC_headLightFlash);
								outInt[35] = LC_headLightFlash;
							}

							if (LC_dippedHighBeamReverter)
							{
								if (carHDC->getLC_dippedHighBeamReverter())
									outInt[35] = 0;
								else
									outInt[35] = 1;
								carHDC->setLC_dippedHighBeamReverter(outInt[35]);
							}
						}
					}
					// Fog lights
					{
						int curFogState = carHDC->getLC_FogState();
						if (LC_FogMore) // If there is a Positive edge on More
						{
							if (LC_FogMore != carHDC->getLC_FogMore())
							{
								carHDC->setLC_FogMore(LC_FogMore);
								if (curFogState < 2)
								{
									curFogState++;
									carHDC->setLC_FogState(curFogState);
								}
							}
						}
						else
							carHDC->setLC_FogMore(LC_FogMore);
						if (LC_FogLess) // If there is a Positive edge on Less
						{
							if (LC_FogLess != carHDC->getLC_FogLess())
							{
								carHDC->setLC_FogLess(LC_FogLess);
								if (curFogState > 0)
								{
									curFogState--;
									carHDC->setLC_FogState(curFogState);
								}
							}
						}
						else
							carHDC->setLC_FogLess(LC_FogLess);
						switch (curFogState)
						{
							case 0:
							{
								outInt[36] = 0;
								outInt[37] = 0;
								break;
							}
							case 1:
							{
								outInt[36] = 1;
								outInt[37] = 0;
								break;
							}
							case 2:
							{
								outInt[36] = 1;
								outInt[37] = 1;
								break;
							}
							default:
							{
								outInt[36] = 0;
								outInt[37] = 0;
								break;
							}
						}
					}
					// Left push
					{
						outInt[38] = LC_leftPush;
					}
				// End Lighting control
				// Start Wiper control
					int WC_frontWipingInt = GetBits(Data[1], 5, 5); // Position 1
					int WC_frontWipingPos1 = GetBits(Data[1], 6, 6); // Position 2
					int WC_frontWipingPos2 = GetBits(Data[1], 7, 7); // Position 3
					int WC_frontAutoWiping = GetBits(Data[1], 4, 4); // POS_BAS_UN_CRAN
					int WC_frontOff = !WC_frontWipingInt && !WC_frontWipingPos1 && !WC_frontWipingPos2 && !WC_frontAutoWiping; // Position 0 > outInt[38]
					int WC_frontWindshieldWasher = GetBits(Data[1], 3, 3); // POS_TIR_UN_CRAN
					int WC_rearWiping = GetBits(Data[1], 2, 2); // ROT_1_CRAN_ESS
					int WC_rearWindshieldWasher = GetBits(Data[1], 1, 1); // ROT_2_CRAN_ESS
					int WC_pushButton = GetBits(Data[1], 0, 0); // PUSH_DT_ET_HDC
					int WC_rearOff = !WC_rearWiping && !WC_rearWindshieldWasher;
					// Front wiper
					{
						outInt[39] = WC_frontOff;
						outInt[40] = WC_frontWipingInt;
						outInt[41] = WC_frontWipingPos1;
						outInt[42] = WC_frontWipingPos2;
						outInt[43] = WC_frontAutoWiping;
						outInt[44] = WC_frontWindshieldWasher;
					}
					// Rear wiper
					{
						outInt[45] = WC_rearOff;
						if (WC_rearWindshieldWasher)
							outInt[46] = 1;
						else
							outInt[46] = WC_rearWiping;
						outInt[47] = WC_rearWindshieldWasher;
					}
					// Push button
					{
						outInt[48] = WC_pushButton;
						//printf("%d", WC_pushButton);
					}
				// End Wiper control
				// Start indicators
					int I_left = GetBits(Data[2], 6, 6);
					int I_right = GetBits(Data[2], 7, 7);
					int I_off = !I_left && !I_right;
					{
						outInt[49] = I_left;
						outInt[50] = I_right;
						outInt[51] = I_off;
						if (I_left || I_right)
						{
							if (timeSinceIndicatorHDC.run() > 1)
							{
								timeSinceIndicatorHDC.init();
								pcanUsb->SendMsg(0x102, sizeof(playIndicatorSound), playIndicatorSound); // 1Hz
							}
						}
						else
						{
							if (timeSinceIndicatorHDC.run() > 1)
							{
								timeSinceIndicatorHDC.init();
								pcanUsb->SendMsg(0x102, sizeof(stopIndicatorSound), stopIndicatorSound); // 1Hz
							}
						}
					}
				// End indicators
				// Start Steering buttons
					outInt[52] = GetBits(Data[3], 7, 7); // LVV on
					outInt[53] = GetBits(Data[3], 6, 6); // RVV on
					outInt[54] = !outInt[52] && !outInt[53]; // LVV/RVV off
					outInt[55] = GetBits(Data[3], 5, 5); // LVV/RVV +
					outInt[56] = GetBits(Data[3], 4, 4); // LVV/RVV -
					outInt[57] = GetBits(Data[3], 3, 3); // Deactivation
					outInt[58] = GetBits(Data[3], 2, 2); // safety distance increment
					outInt[59] = GetBits(Data[3], 1, 1); // safety distance decrement
					outInt[60] = GetBits(Data[3], 0, 0); // ARTIV selection request

					outInt[61] = GetBits(Data[4], 7, 7); // Horn command
					outInt[62] = GetBits(Data[4], 6, 6); // Voice command
					outInt[63] = GetBits(Data[4], 5, 5); // Measurement of space available
					outInt[64] = GetBits(Data[4], 4, 4); // Configurable key
					outInt[65] = GetBits(Data[4], 3, 3); // Upper rheostating overflow
					outInt[66] = GetBits(Data[4], 2, 2); // Lower rheostating overflow
					outInt[67] = GetBits(Data[4], 1, 1); // Status of LVV/RVV cycling monostable push
					outInt[68] = GetBits(Data[4], 0, 0); // Status of LVV and RVV deselection monostable push
				// End Steering buttons
					break;
				}
				case 0x21F: // Trame RADIO, 3 bytes
				{ 
				// Start Commande radio #1
					{
						outInt[69] = GetBits(Data[0], 0, 0); // List key
						outInt[70] = GetBits(Data[0], 1, 1); // Mode / Phone
						outInt[71] = GetBits(Data[0], 2, 2); // Volume-
						outInt[72] = GetBits(Data[0], 3, 3); // Volume+
						outInt[73] = GetBits(Data[0], 4, 4); // Scan - overflow
						outInt[74] = GetBits(Data[0], 5, 5); // Scan + overflow
						outInt[75] = GetBits(Data[0], 6, 6); // Descending search
						outInt[76] = GetBits(Data[0], 7, 7); // Ascending search
					}
				// End Commande radio #1
				// Start Commande radio #2
					{
						// The SCAN knob counter has no end stop, value may be between -128 and +127, a specific development is needed.
						outInt[77] = GetBits(Data[1], 0, 7); // SCAN knob counter
					}
				// End Commande radio #2
				// Start Commande radio #3
					{
						// The first 5 bits are not used 
						//outInt[78] = GetBits(Data[2], 0, 0); // LIBRE_6
						//outInt[79] = GetBits(Data[2], 1, 1); // LIBRE_6
						//outInt[80] = GetBits(Data[2], 2, 2); // LIBRE_6
						//outInt[81] = GetBits(Data[2], 3, 3); // LIBRE_6
						//outInt[82] = GetBits(Data[2], 4, 4); // LIBRE_6
						//outInt[83] = GetBits(Data[2], 5, 5); // LIBRE_6
						outInt[84] = GetBits(Data[2], 6, 6); // Source push
						outInt[85] = GetBits(Data[2], 7, 7); // Radio command validation
					}
				// End Commande radio #3
					break;
				}
				case 0x0A2: // Trame CAR_VMF_DSGN, 6 bytes
				{
				// Start Commande designateur
					{
						// Counter of the VMF navigation menu needs a specific development. //86
						/*if (!havecheck1)
						{
							curData1 = GetBits(Data[0], 0, 7);
							outInt[86] = 0;
							havecheck1 = true;
							printf("set havecheck1 to true \n");
							printf("outInt[86]:%d \n", outInt[86]);
							printf("curData: %d \n", curData1);
						}
						else
						{
							outInt[86] = GetBits(Data[0], 0, 7) - curData1;
							curData1 = GetBits(Data[0], 0, 7);
							printf("get havecheck1 is true \n");
							printf("outInt[86]:%d \n", outInt[86]);
							printf("curData: %d \n", curData1);
							if (outInt[86] != 0)
							{
								printf("get 86");
							}
						}*/
						outInt[86] = GetBits(Data[0], 0, 7); // Counter of the VMF navigation menu

						outInt[87] = GetBits(Data[1], 0, 0); // Counter of the VMF navigation menu
						outInt[88] = GetBits(Data[1], 1, 1); // Voice command
						outInt[89] = GetBits(Data[1], 2, 2); // Left-hand push
						outInt[90] = GetBits(Data[1], 3, 3); // Designator mode key
						outInt[91] = GetBits(Data[1], 4, 4); // Designator menu key
						outInt[92] = GetBits(Data[1], 5, 5); // Designator escape key
						outInt[93] = GetBits(Data[1], 6, 6); // Lower overflow of the navigation knob
						outInt[94] = GetBits(Data[1], 7, 7); // Upper overflow of the navigation knob

						//outInt[95] = GetBits(Data[2], 0, 6); // LIBRE_7
						outInt[96] = GetBits(Data[2], 7, 7); // Access to KML phone directory
					}
				// End Commande designateur
				// Start Commande designateur CMB
					{
						// Counter of the combined navigation menu needs a specific development. //97
						outInt[97]	= GetBits(Data[3], 0, 7); // Counter of the combined navigation menu
						/*if (!havecheck2)
						{
							curData2 = GetBits(Data[3], 0, 7);
							outInt[97] = 0;
							havecheck2 = true;
							printf("set havecheck2 to true \n");
							printf("outInt[97]:%d \n", outInt[97]);
							printf("curData2: %d \n", curData1);
						}
						else
						{
							outInt[97] = GetBits(Data[3], 0, 7) - curData2;
							curData2 = GetBits(Data[3], 0, 7);
							printf("get havecheck2 is true \n");
							printf("outInt[97]:%d \n", outInt[97]);
							printf("curData2: %d \n", curData2);
							if (outInt[97]!=0)
							{
								printf("get 97");
							}
						}*/
						
						outInt[98]	= GetBits(Data[4], 4, 4); // Designator escape key of the CMB
						outInt[99]	= GetBits(Data[4], 5, 5); // Designator validation key
						outInt[100]	= GetBits(Data[4], 6, 6); // Lower overflow of the navigation knob on CMB
						outInt[101] = GetBits(Data[4], 7, 7); // Upper overflow of the navigation knob on CMB
					}
				// End Commande designateur CMB
				// Start Autres commandes
					{
						outInt[102] = GetBits(Data[4], 0, 0); // Lower overflow of the volume knob
						outInt[103] = GetBits(Data[4], 1, 1); // Upper overflow of the volume knob
						//outInt[104] = GetBits(Data[4], 2, 2); // LIBRE_1
						outInt[105] = GetBits(Data[4], 3, 3); // A/C air recycling flap command
						
						// Counter of the VCI volume needs a specific development. //106
						outInt[106] = GetBits(Data[5], 0, 7); // Counter of the VCI volume
						/*if (!havecheck3)
						{
							curData3 = GetBits(Data[5], 0, 7);
							outInt[106] = 0;
							havecheck3 = true;
							printf("set havecheck3 to true \n");
							printf("outInt[106]:%d \n", outInt[106]);
							printf("curData3: %d \n", curData3);
						}
						else
						{
							outInt[106] = GetBits(Data[5], 0, 7) - curData3;
							curData3 = GetBits(Data[5], 0, 7);
							printf("get havecheck3 is true \n");
							printf("outInt[106]:%d \n", outInt[106]);
							printf("curData3: %d \n", curData3);
							if (outInt[106] != 0)
							{
								printf("get 106");
							}
						}*/

					}
				// End Autres commandes
					break;
				}
				default:
					break;
			}
		}
		sendUDPPacket(s, outFlt, NB_FLT_OUT, outInt, NB_INT_OUT);

		int dataOut[DATA_OUT_SIZE];
		VENCom* venCom = VENCreate();
		/* VEN initialization*/
		VENInit(venCom, "239.255.0.1", 63999, VENSendNonBuffered);

		int VenInt[DATA_OUT_SIZE];

		VenInt[0] = outInt[55];
		//VenInt[0] = temp == 0? temp = 1:temp =0;
		VenInt[1] = outInt[56];
		VenInt[2] = outInt[57];
		VenInt[3] = outInt[63];
		VenInt[4] = outInt[71];
		VenInt[5] = outInt[72];
		VenInt[6] = outInt[96];
		VenInt[7] = outInt[99];
		VenInt[8] = outInt[91];
		VenInt[9] = outInt[92];
		VenInt[10] = outInt[97];
		VenInt[11] = outInt[86];
		VenInt[12] = outFlt[106];
		//VenInt[12] = outInt[61]
		//ViolinSolo;
		VenInt[13] = outInt[38];//left hand push button
		VenInt[14] = outInt[48];//right hand push button
		//ViolinSolo 11.5.2017
		VenInt[15] = outInt[71];//// Volume-
		VenInt[16] = outInt[72];//// Volume+
		VenInt[17] = outInt[69];//// List key
		VenInt[18] = outInt[84];//// Source push
		VenInt[19] = outInt[85];//// Scroll push
		VenInt[20] = outInt[77];//// Scroll 

		if (temp != VenInt[13]) {
			//printf("\n ----VenInt[13]:%d------", VenInt[13]);
			//temp = VenInt[13];
		}

		for (int i = 0; i < NB_INT_OUT; i++) {
			if (outInt[i] != 0) {
				printf(" [%d]:%d", i, outInt[i]);
			}
			if (i == NB_FLT_OUT - 1) {
				printf("\n");
			}
		}

		// ViolinSolo 2018-5-27 -- begin
		/*for (int i = 0; i < DATA_OUT_SIZE; i++)
		{
			printf(" [%d]:%d", i, VenInt[i]);
		}*/
		/*printf(" [%d]:%d", 18, VenInt[18]);
		printf(" [%d]:%d", 19, VenInt[19]);
		printf(" [%d]:%d", 20, VenInt[20]);
		printf("\n");*/
		// ViolinSolo 2018-5-27 -- end
		
		/*
		printf("VenInt[0-%d]: %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d,| %d, %d,| %d, %d, %d, %d;\n", DATA_OUT_SIZE,
			VenInt[0], VenInt[1], VenInt[2], VenInt[3], VenInt[4], 
			VenInt[5], VenInt[6], VenInt[7], VenInt[8], VenInt[9],
			VenInt[10], VenInt[11], VenInt[12], VenInt[13], VenInt[14],
			VenInt[15], VenInt[16], VenInt[17], VenInt[18]);*/
		//VenInt[13] = curData2;
		//VenInt[14] = curData3;
		//VenInt[15] = curData1;
		if (temp != VenInt[17]) {
			printf("\n ----VenInt[15]:%d------", VenInt[17]);
			temp = VenInt[17];
		}
		/* write a message on the VEN Bus*/
		for (int i = 0; i < DATA_OUT_SIZE; ++i)
		{
			dataOut[i] = outInt[52 + i];
			//printf("%d", dataOut[i]);
			//printf("%d", VenInt[i]);
		}
		//printf("\n");
		VENMessageWrite(venCom, "FROM_ACQUI", "ACQUI", VENTypeInt, &VenInt, DATA_OUT_SIZE);

		/* release the allocated ressources */
		VENRelease(venCom);
	};
	delete s;
	return 0;
}
